package com.lagou;

import com.lagou.server.StartServer;
import com.lagou.server.ZkServerHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class ServerBootstrap implements CommandLineRunner {

    @Autowired
    private ZkServerHandler zkServerHandler;

    public static void main(String[] args) throws InterruptedException {
        SpringApplication.run(ServerBootstrap.class, args);
    }


    public void run(String... args) throws Exception {

        //服务器启动的端口通过启动参数传递
        int port = Integer.parseInt(args[0]);


        StartServer.startServer("127.0.0.1", port);
        zkServerHandler.registerToZk(port);
    }
}
